<%@page import="cn.edu.nju.ws.sview.views.Group"%>
<%@page import="cn.edu.nju.ws.sview.views.User"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Group Manage</title>
	<link rel="icon" href="/sview/favicon.ico" />
	<link rel="stylesheet" type="text/css" href="/sview/css/group/group.css">
	<link rel="stylesheet" type="text/css" href="/sview/css/layout.css">
	<script type="text/javascript" src="/sview/script/jquery.js"></script>
<script type="text/javascript" src="/sview/script/global.js"></script>
  <link rel="stylesheet" href="../css/group/bootstrap.min.css" type="text/css"></link>
  </head>
  <%
  	String lang = request.getParameter("lang");
       if (lang != null && lang.equals("zh")) {
			request.getRequestDispatcher("gmanage_zh.jsp").forward(
					request, response);
		} else if (lang == null) {
			lang = "en";
		}
       String from = request.getParameter("from");
       
    	String uname = (String) session.getAttribute("user"); 
    	if(uname ==  null){
    		response.sendRedirect("/sview/views/index.jsp");
    	}else{
    	User user = new User(uname);
  		HashSet<Integer> groups = user.getGroups();
  %>
  <body>
    <jsp:include page="/vheader.jsp" flush="true" />
    <div id="container" class="container">
	    <div class="gHeader"><span class="large">Group Manage</span></div>
	    <div id="gmanage_ection" class="section">
	        <%String href="/sview/group/gcreate.jsp";
	          if(from!=null){
	        	  href=  href+"?from="+from;
	          }
	          
	        %>
	    	<div id="gcreate"><span><a href="<%=href %>" class="form-button" style="text-decoration: none;">Create a Group</a></span></div>
	    	<div id="glist">
				<%if(groups != null && groups.size()>0){ %>
				<p style="margin-top: 20px;" class="title">My Groups:</p>
				<div class="content">
				<div class="tableDiv">
					<table>
						<thead>
							<tr>
				    			<td>Group Name</td>
				    			<td>Group Profile</td>
				    		</tr>
						</thead>
						<tbody id="groups">
						<%for(Integer g : groups){ 
							String req = "/sview/group/gdetail.jsp?gid="+g;
							String profile = "/sview/group/gprofile.jsp?gid="+g+"&uname="+uname;
							%>
							<tr>
								<td><a href=<%=req %>><%=Group.getGroupNameById(g) %></a></td>
								<td><a href=<%=profile %>><%=Group.getGroupNameById(g) %> Profile</a></td>
							</tr>
						<%} %>
						</tbody>
					</table>
				</div>
				</div>
				<%-- <ul id="groups">
				<%for(Integer g : groups){ 
					String req = "group/gdetail.jsp?gid="+g;
					%>
					<li><a href=<%=req %>><%=Group.getGroupNameById(g) %></a></li>
				<%} %>
				</ul> --%>
				<%} %>
			</div>
	    </div>
    </div>
	<input type="hidden" id="display-lang" value="en" />
	<%if(from!=null){ %>
	   	<input type="hidden" id="from" value="<%=from %>" />
	<%} %>
   <jsp:include page="/vfooter.jsp"></jsp:include>
  </body>
  <%} %>
</html>
